<h3><%= l(:label_my_contacts_stats) %></h3> 


<% 
  from = Date.civil(Date.today.year, Date.today.month, 1)
  to = (from >> 1) - 1
%>

<table class="list">
<tbody>
  <tr>
    <td><%= l(:label_contacts_created) %></td>
    <td><%= Contact.count(:conditions => {:author_id => @user.id, :created_on => from..to}) %></td>
  </tr>
  <tr>
    <td><%= l(:label_deals_created) %></td>
    <td><%= Deal.count(:conditions => {:author_id => @user.id, :created_on => from..to}) %></td>
  </tr>
  <% Deal.find(:all, :select => "#{DealStatus.table_name}.name, #{Deal.table_name}.status_id,  COUNT(DISTINCT #{Deal.table_name}.price) AS count, SUM(DISTINCT #{Deal.table_name}.price) AS total_sum", 
              :joins => "JOIN #{DealStatus.table_name} ON #{Deal.table_name}.status_id = #{DealStatus.table_name}.id", 
              :conditions => {:author_id => @user.id, :created_on => from..to},
              :group => "#{DealStatus.table_name}.name, #{DealStatus.table_name}.color, #{Deal.table_name}.status_id").each do |status| %>
  <tr>
    <td style=<%= "background-color:#{status.status.color_name};color:white;"%>>
      <span class="deal-status" %> >
			<%= h status.name %> 
		  </span>
		</td>
    <td><%= status.count %></td>
  </tr>
  <% end %>
</tbody>
</table>


<% content_for(:header_tags) do %>
	<%= javascript_include_tag :contacts, :plugin => 'redmine_contacts'  %>
  <%= stylesheet_link_tag :contacts, :plugin => 'redmine_contacts' %> 
<% end %>
